/**
 *
 * 大炮
 *
 */
class Cannon extends egret.DisplayObjectContainer {

    private _dizuoArm: dragonBones.FastArmature;
    private _paotongArm: dragonBones.FastArmature;
    private _dizuoDisplay: egret.DisplayObjectContainer;
    private _paotongDisplay: egret.DisplayObjectContainer;

    public constructor() {

        super();

        this._paotongArm = AniFactory.produce('cannon/paotong/ani.json','cannon/paotong/texture.json','cannon/paotong/texture.png', 'paotong');
        this._dizuoArm   = AniFactory.produce('cannon/dizuo/ani.json','cannon/dizuo/texture.json','cannon/dizuo/texture.png', 'dizuo');
        this._paotongDisplay = this._paotongArm.display;
        this._dizuoDisplay = this._dizuoArm.display;

        this.addChild(this._dizuoDisplay);
        this.addChild(this._paotongDisplay);

        this.resetCannon(false);
    }

    public resetCannon(isEase: Boolean): void {

        var that: Cannon = this;

        this._dizuoDisplay.x = 203;
        this._dizuoDisplay.y = 425;
        that._paotongArm.animation.gotoAndPlay('ready');
        that._dizuoArm.animation.gotoAndPlay('ready');

        if(isEase) {
            egret.Tween.get(this._paotongDisplay).to({
                x: 195,
                y: 350,
                rotation: -20
            }, 1500);
        } else {
            this._paotongDisplay.x = 195;
            this._paotongDisplay.y = 350;
            this._paotongDisplay.rotation = -20;
        }
    }

    public fireCannon(callback?: Function): void {

        var that: Cannon = this;

        egret.Tween.get(this._paotongDisplay).to({
            x: 200,
            y: 355,
            rotation: -40
        },1500).call(function() {
            that._paotongArm.animation.gotoAndPlay('fire');
            that._dizuoArm.animation.gotoAndPlay('fire');
            callback && callback();
        }).wait(1000).call(function() {
            that.resetCannon(true);
        });
    }
}
